#-*-encoding=utf-8-*-
steps = [
    FlowStep(
        name=u'init',
        title=u'会议室申请',
        fields=['title', 'description', 'dept', 'start', 'end', 'master', 'writer', 'attendee', 'resource', 'room'],
        responsibles=u'[request.principal.id]',
    actions=[
        FlowStepAction(
            name=u'book',
            title=u'预订',
            nextsteps=['report'],
            trigger=ur"""## 设置标签
sheet['subjects'] = [u'Booked', sheet['room']]
IObjectIndexer(sheet).reindexObject()

## 发送通知

# 通知人
to_ids = (sheet['master'] or []) + (sheet['writer'] or []) + (sheet['attendee'] or [])

reviewer = flowsettings['reviewer']
if reviewer:
    to_ids = to_ids + reviewer

# set message body
url = absoluteURL(sheet, request)
body = ("会议将在 %s 举行. 会议开始时间： %s. \n\n会议详细信息在这里： %s " % (sheet['room'], sheet['start'], url))

notifier_message.send('会议通知: ' + sheet['title'], body, to_ids)""",
            finish_condition=u''
)
])
,

    FlowStep(
        name=u'report',
        title=u'会议报告',
        fields=['title', 'start', 'end', 'resource', 'room', 'report'],
        responsibles=u'sheet["creators"]',
    actions=[
        FlowStepAction(
            name=u'modify',
            title=u'重新提交',
            nextsteps=['report'],
            trigger=ur"""## 修改标签

sheet['subjects'] = [u'Booked', sheet['room']]
IObjectIndexer(sheet).reindexObject()

## 发送通知
to_ids = set(sheet['master']) + \
         set(sheet['writer']) + \
         set(sheet['attendee'])

reviewer = flowsettings['reviewer']
if reviewer:
    to_ids += set([reviewer])

# set message body
room = sheet['room']
time = sheet['start']
url = absoluteURL(sheet, request)
body = ("会议将在 %s 举行. 会议开始时间： %s. \n\n会议详细信息在这里： %s " %  (room, time, url))

notifier_message.send('会议通知: ' + sheet['title'], body, to_ids)
""",
            finish_condition=u''
),

        FlowStepAction(
            name=u'finish',
            title=u'会议结束',
            nextsteps=[],
            trigger=ur"""## set tags
sheet['subjects'] = [u'Finished', sheet['room']]
IObjectIndexer(sheet).reindexObject()""",
            finish_condition=u''
),

        FlowStepAction(
            name=u'cancel',
            title=u'取消会议',
            nextsteps=[],
            trigger=ur"""## set tags
sheet['subjects'] = [u'Booked', sheet['room']]
IObjectIndexer(sheet).reindexObject()

# 通知人
to_ids = set(sheet['master']) + \
         set(sheet['writer']) + \
         set(sheet['attendee']) + \
         set(sheet['creators'])


# set message body
url = absoluteURL(sheet, request)
body = ("对不起, 会议 '%s' (%s) 已经取消. 详细请查看： %s ." %  (sheet['title'], sheet['time'], url))

notifier_message.send('会议取消: ' + sheet['title'], body, to_ids)
""",
            finish_condition=u''
)
])
]
